﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vboot.App
{
    public static class EnumHelper
    {
        public static string ToDescription(this Enum val)
        {
            var type = val.GetType();
            var memberInfo = type.GetMember(val.ToString());
            var attributes = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
            //如果没有定义描述，就把当前枚举值的对应名称返回
            if (attributes == null || attributes.Length != 1) return val.ToString();

            return (attributes.Single() as DescriptionAttribute).Description;
        }
        public static T ToEnum<T>(this string str)
        {
            return (T)Enum.Parse(typeof(T), str);
        }
        public static T GetEnumValue<T>(string str) where T : struct, IConvertible
        {
            Type enumType = typeof(T);
            if (!enumType.IsEnum)
            {
                throw new Exception("T must be an Enumeration type.");
            }
            T val;
            return Enum.TryParse<T>(str, true, out val) ? val : default(T);
        }
        public static string GetEnumDesc<T>(T tField)
        {
            var description = string.Empty; //结果
            var inputType = tField.GetType(); //输入的类型
            var descType = typeof(DescriptionAttribute); //目标查找的描述类型

            var fieldStr = tField.ToString();                //输入的字段字符串
            var field = inputType.GetField(fieldStr);        //目标字段

            var isDefined = field.IsDefined(descType, false);//判断描述是否在字段的特性
            if (isDefined)
            {
                var EnumAttributes = (DescriptionAttribute[])field        //得到特性信息
                    .GetCustomAttributes(descType, false);
                description = EnumAttributes.FirstOrDefault()?.Description ?? string.Empty;
            }
            return description;
        }
        public enum DocumentStatus
        {
            [Description("新建")]
            A,
            [Description("暂存")]
            Z,
            [Description("审核中")]
            B,
            [Description("已审核")]
            C,
            [Description("重新审核")]
            D,
        }

        public enum CloseStatus
        {
            [Description("未关闭")]
            A,
            [Description("已关闭")]
            B,
        }

        public enum OrgName
        {
            [Description("100150")]
            BK,
            [Description("1")]
            GL,
            [Description("100154")]
            GM
        }



        //业务关闭
        public enum MRPCloseStatus
        {
            [Description("正常")]
            A,
            [Description("业务关闭")]
            B,
        }
        //业务冻结
        public enum FMRPFREEZESTATUS
        {
            [Description("正常")]
            A,
            [Description("业务冻结")]
            B,
        }

        public enum FORBIDSTATUS
        {
            [Description("否")]
            A,
            [Description("是")]
            B,
        }
        public enum FPICKMTRLSTATUS
        {
            [Description("未领料")]
            _1,
            [Description("部分领料")]
            _2,
            [Description("全部领料")]
            _3,
            [Description("超额领料")]
            _4,
        }
        public enum FPRODUCTTYPE
        {
            [Description("主产品")]
            _1,
            [Description("联产品")]
            _2,
            [Description("副产品")]
            _3,
        }

        public enum ORGNUMBER
        {
            [Description("线一事业部")]
            GL01,
            [Description("线二事业部")]
            GL02,
            [Description("线三事业部")]
            GL03,
            [Description("线四事业部")]
            GL04,
            [Description("广东柏科电源有限公司")]
            BK,
            [Description("广东光沐半导体科技有限公司")]
            GM,
            [Description("广东微观科技有限公司")]
            GL,
            [Description("GL01")]
            线一事业部,
            [Description("GL02")]
            线二事业部,
            [Description("GL03")]
            线三事业部,
            [Description("GL04")]
            线四事业部,
            [Description("BK")]
            广东柏科电源有限公司,
            [Description("GM")]
            广东光沐半导体科技有限公司,
            [Description("GL")]
            广东微观科技有限公司,
        }

        public enum FEXCHANGETYPE
        {
            [Description("固定汇率")]
            HLTX01_SYS,
            [Description("即期汇率")]
            HLTX02_SYS,
            [Description("预算汇率")]
            HLTX03_SYS,
        }

        public enum FSETTLECURRENCY
        {
            [Description("人民币")]
            PRE001,
            [Description("香港元")]
            PRE002,
            [Description("欧元")]
            PRE003,
            [Description("日本日圆")]
            PRE004,
            [Description("新台币元")]
            PRE005,
            [Description("英镑")]
            PRE006,
            [Description("美元")]
            PRE007,
        }

        public enum FACCTYPE
        {
            [Description("数量验收")]
            Q,
            [Description("金额验收")]
            A,
            [Description("比例验收")]
            R,
        }
        public enum CHANGEFACCTYPE
        {
            [Description("Q")]
            数量验收,
            [Description("A")]
            金额验收,
            [Description("R")]
            比例验收,
        }

        public enum GLDEPTID
        {
            [Description("Q")]
            数量验收,
            [Description("A")]
            金额验收,
            [Description("R")]
            比例验收,
        }
        public enum FREQUESTTYPE
        {
            [Description("物料")]
            Material,
            [Description("财产")]
            Property,
            [Description("费用")]
            Expense,
        }
        /// <summary>
        /// 税外价
        /// </summary>
        public enum FISPRICEEXCLUDETAX
        {
            [Description("价内税")]
            A,
            [Description("价外税")]
            B,
        }

        public enum FPROBILLSTATUSNAME
        {
            [Description("确认开工")]
            _1,
            [Description("工序进行")]
            _2,
            [Description("工序完成")]
            _3,
        }
        /// <summary>
        /// 20240527z add
        /// </summary>
        public enum Enum_In_stock_detail_sort
        {
            [Description("入库前接收")]
            BeforeIn = 1

        }
    }
}
